

const swith_tab = () => {
  const tabsNav = Array.from(document.querySelector('.tabs-nav').children);
  const tabsContent = document.querySelector('.tabs-content');
  tabsNav.forEach((d, i) => {
    d.onclick = () => {
      tabsNav.forEach((dd) => {
        dd.classList.remove('active');
      });
      d.classList.add('active');
      tabsContent.style.transform = `translateX(-${i * 100}%)`;
    };
  });
};

const joinSubmit = () => {
  const schoolTake = document.getElementById('schoolTake');
  const yearTake = document.getElementById('yearTake');
  const email = document.getElementById('email');
  const joinSubmit = document.getElementById('join-submit');
  const joinAlert = document.getElementById('join-alert');
  const reSubmit = document.querySelector('#joined > a');
  bind(joinSubmit, 'click', () => {
    if (schoolTake.value.trim() === '') {
      showAlert(joinAlert, 'error', 3000, `学校名不符合要求,请重新输入`);
      return false;
    } else if (!Number.parseInt(yearTake.value)) {
      showAlert(
        joinAlert,
        'error',
        3000,
        `入学年份不符合要求(${yearTake.value}),请重新输入`
      );
      return false;
    } else if (
      !/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(
        email.value
      )
    ) {
      showAlert(
        joinAlert,
        'error',
        3000,
        `邮箱地址不符合要求(${email.value}),请重新输入`
      );
      return false;
    }
    showAlert(
      joinAlert,
      'success',
      5000,
      `恭喜您,来自 ${schoolTake.value.trim()} ${Number.parseInt(
        yearTake.value
      )}级 ${email.value}同学,您的报名信息已记录,请关注您的邮件`
    );
    document.getElementById('join').classList.toggle('active');
    document.getElementById('joined').classList.toggle('active');
  });
  bind(reSubmit, 'click', () => {
    document.getElementById('join').classList.toggle('active');
    document.getElementById('joined').classList.toggle('active');
  });
};

// window.onload = function () {
  swith_tab();
  inputYear(document.getElementById('enter-year'), 1990, 2040);
  inputDualColSelect(document.getElementById('school-pick'), schools);
  joinSubmit();
// };